﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using 基于WPF的电缆采样数据分析系统.Models.Enums;

namespace 基于WPF的电缆采样数据分析系统.Models.Dbs.DbService
{
    /// <summary>
    /// 任务导出表服务
    /// </summary>
    public class TaskDataInfoDAOService
    {
        /// <summary>
        /// 单例模型
        /// </summary>
        public static TaskDataInfoDAOService Instance = new TaskDataInfoDAOService(App.GetService<TDRDbContext>());

        /// <summary>
        /// 数据库上下文
        /// </summary>
        private readonly TDRDbContext db;

        /// <summary>
        /// 构造器
        /// </summary>
        /// <param name="_db"></param>
        public TaskDataInfoDAOService(TDRDbContext _db)
        {
            db = _db;
        }



        /// <summary>
        /// 添加任务导出信息
        /// </summary>
        /// <param name="projectDataInfoDAO"></param>
        /// <returns></returns>
        public RetResult AddTaskDataInfoDAO(TaskDataInfoDAO taskDataInfoDAO)
        {
            try
            {
                db.TaskDataInfoDAOs.Add(taskDataInfoDAO);

                int rows = db.SaveChanges();

                if (rows > 0)
                {
                    return RetResult.Success;
                }

                return RetResult.Fail;
            }
            catch (Exception ex)
            {
                return RetResult.Fail;
            }
        }

        /// <summary>
        /// 获取所有的任务导出数据信息
        /// </summary>
        /// <returns></returns>
        public ObservableCollection<TaskDataInfoDAO> GetTaskDataInfoDAOList()
        {
            try
            {

                ObservableCollection<TaskDataInfoDAO> taskDataInfoDAOs = new ObservableCollection<TaskDataInfoDAO>(db.TaskDataInfoDAOs);

                if (taskDataInfoDAOs.Count > 0)
                {
                    return taskDataInfoDAOs;
                }

                return null;
            }
            catch (Exception ex)
            {
                return null;
            }
        }
    }
}
